package com.dxf.sysadmin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dxf.common.utils.ResultJson;
import com.dxf.sysadmin.entity.Course;
import com.dxf.sysadmin.entity.EvaluteItem;
import com.dxf.sysadmin.entity.qo.ItemQo;
import com.dxf.sysadmin.mapper.EvaluteItemMapper;
import com.dxf.sysadmin.service.EvaluteItemService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 备选项 服务实现类
 */
@Service
public class EvaluteItemServiceImpl extends ServiceImpl<EvaluteItemMapper, EvaluteItem> implements EvaluteItemService {

    /**
     *评价选项分页查询
     */
    @Override
    public ResultJson itemPage(ItemQo qry) {
        Page<EvaluteItem> page = new Page<>(qry.getPage(), qry.getLimit());
        LambdaQueryWrapper<EvaluteItem> eq =null;
        if (qry.getTargetId()!=null){
            eq=new QueryWrapper<EvaluteItem>().lambda()
                    .eq(EvaluteItem::getTargetId, qry.getTargetId());
        }
        IPage<EvaluteItem> iPage = page(page,eq);
        Map<String, Object> map = new HashMap<>(16);
        map.put("rows",iPage.getRecords());
        map.put("total",iPage.getTotal());
        return ResultJson.ok().data(map);
    }

    /**
     *更具id列表删除选项
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public ResultJson deleteItem(List<Long> list) {
        removeByIds(list);
        //TODO
        return ResultJson.ok();
    }

    /**
     *新增或者更新选项
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public ResultJson saveOrUpdateItem(EvaluteItem item) {
        saveOrUpdate(item);
        return ResultJson.ok();
    }
}
